<template>
    <div class="dashboard">
      <div class="chart" ref="chart1"></div>
      <div class="chart" ref="chart2"></div>
      <div class="chart" ref="chart3"></div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        chart1: null,
        chart2: null,
        chart3: null
      }
    },
    mounted() {
      this.initChart1()
      this.initChart2()
      this.initChart3()
    },
    beforeDestroy() {
      this.chart1.dispose()
      this.chart2.dispose()
      this.chart3.dispose()
    },
    methods: {
      initChart1() {
        this.chart1 = this.$echarts.init(this.$refs.chart1)
        const option = {
          title: {
            text: '折线图'
          },
          tooltip: {
            trigger: 'axis'
          },
          xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              data: [820, 932, 901, 934, 1290, 1330, 1320],
              type: 'line'
            }
          ]
        }
        this.chart1.setOption(option)
      },
      initChart2() {
        this.chart2 = this.$echarts.init(this.$refs.chart2)
        const option = {
          title: {
            text: '柱状图'
          },
          tooltip: {
            trigger: 'axis'
          },
          xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              data: [820, 932, 901, 934, 1290, 1330, 1320],
              type: 'bar'
            }
          ]
        }
        this.chart2.setOption(option)
      },
      initChart3() {
        this.chart3 = this.$echarts.init(this.$refs.chart3)
        const option = {
          title: {
            text: '饼图'
          },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: 'Access From',
              type: 'pie',
              radius: '50%',
              data: [
                { value: 1048, name: 'Search Engine' },
                { value: 735, name: 'Direct' },
                { value: 580, name: 'Email' },
                { value: 484, name: 'Union Ads' },
                { value: 300, name: 'Video Ads' }
              ],
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        }
        this.chart3.setOption(option)
      }
    }
  }
  </script>
  
  <style scoped>
  .dashboard {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    padding: 20px;
  }
  .chart {
    width: 300px;
    height: 300px;
    margin: 20px;
    border: 1px solid #ccc;
    border-radius: 8px;
    background-color: #fff;
  }
  </style>
  